package com.jctrip.hotel.source.xxl.dossen.thread;

import com.jctrip.hotel.common.constant.RedisKeyConstant;
import com.jctrip.hotel.common.context.BeanContext;
import com.jctrip.hotel.common.util.RedisUtil;
import com.jctrip.hotel.source.service.dossen.DossenService;
import com.jctrip.hotel.source.service.dossen.DossenTaskService;
import org.apache.commons.lang.StringUtils;

/**
 * @Author：Haruhi
 * @description:
 * @Date：2023/11/6 15:20
 * @Package：com.jctrip.hotel.source.xxl.dossen.thread
 * @Project：hotel-main
 */
public class SyncDossenPicTaskThread implements Runnable {
    private final String appId;
    private final String secret;

    public SyncDossenPicTaskThread(String appId, String secret) {
        this.appId = appId;
        this.secret = secret;
    }

    @Override
    public void run() {
        RedisUtil redisUtil = BeanContext.getApplicationContext().getBean(RedisUtil.class);
        DossenTaskService dossenTaskService = BeanContext.getApplicationContext().getBean(DossenTaskService.class);
        while (redisUtil.lGetListSize(RedisKeyConstant.HOTEL_MAIN_DOSSEN_PIC_LIST) > 0) {
            String hotelId = (String) redisUtil.rightPop(RedisKeyConstant.HOTEL_MAIN_DOSSEN_PIC_LIST);
            if (StringUtils.isBlank(hotelId)) {
                continue;
            }
            dossenTaskService.syncDossenPic(appId, secret, hotelId);
        }
    }
}
